package com.zhou.JavaAndroidFirm.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.jaydenxiao.androidfire.bean.VideoData;
import com.zhou.JavaAndroidFirm.R;
import com.zhou.JavaAndroidFirm.utils.ViewHolderHelper;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * @author Administrator
 * @date 2018/7/18 0018
 * @des
 */
public class VideoAdapter extends CommonRecycleViewAdapter<VideoData> {
    public VideoAdapter(Context context, int layoutId, List mDatass) {
        super(context, layoutId, mDatass);
    }


    @Override
    public void convert(ViewHolderHelper helper, VideoData videoData) {
        helper.setImageRoundUrl(R.id.iv_logo, videoData.getTopicImg());
        helper.setText(R.id.tv_from, videoData.getTopicName());
        helper.setText(R.id.tv_play_time, String.format(mContext.getResources().getString(R.string.video_play_times), String.valueOf(videoData.getPlayCount())));
        JCVideoPlayerStandard standard = helper.getView(R.id.videoplayer);
        boolean setUp = standard.setUp(videoData.getMp4_url(),
                JCVideoPlayerStandard.SCREEN_LAYOUT_LIST,
                TextUtils.isEmpty(videoData.getDescription()) ? videoData.getTitle() : videoData.getDescription()
        );
        if (setUp) {
            Glide.with(mContext)
                    .setDefaultRequestOptions(new RequestOptions()
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .centerCrop()
                            .error(R.drawable.ic_empty_picture)
                    )
                    .load(videoData.getCover())
                    .transition(DrawableTransitionOptions.withCrossFade()) //动画渐变加载
                    .into(standard.thumbImageView);
        }

    }
}
